1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.DtlsConnectionT;
26 
27 public  import gio.AsyncResultIF;
28 public  import gio.Cancellable;
29 public  import gio.TlsCertificate;
30 public  import gio.TlsDatabase;
31 public  import gio.TlsInteraction;
32 public  import gio.c.functions;
33 public  import gio.c.types;
34 public  import glib.ByteArray;
35 public  import glib.ErrorG;
36 public  import glib.GException;
37 public  import glib.MemorySlice;
38 public  import glib.Str;
39 public  import glib.c.functions;
40 public  import gobject.ObjectG;
41 public  import gobject.Signals;
42 public  import std.algorithm;
43 
44 
45 /**
46  * #GDtlsConnection is the base DTLS connection class type, which wraps
47  * a #GDatagramBased and provides DTLS encryption on top of it. Its
48  * subclasses, #GDtlsClientConnection and #GDtlsServerConnection,
49  * implement client-side and server-side DTLS, respectively.
50  * 
51  * For TLS support, see #GTlsConnection.
52  * 
53  * As DTLS is datagram based, #GDtlsConnection implements #GDatagramBased,
54  * presenting a datagram-socket-like API for the encrypted connection. This
55  * operates over a base datagram connection, which is also a #GDatagramBased
56  * (#GDtlsConnection:base-socket).
57  * 
58  * To close a DTLS connection, use g_dtls_connection_close().
59  * 
60  * Neither #GDtlsServerConnection or #GDtlsClientConnection set the peer address
61  * on their base #GDatagramBased if it is a #GSocket — it is up to the caller to
62  * do that if they wish. If they do not, and g_socket_close() is called on the
63  * base socket, the #GDtlsConnection will not raise a %G_IO_ERROR_NOT_CONNECTED
64  * error on further I/O.
65  *
66  * Since: 2.48
67  */
68 public template DtlsConnectionT(TStruct)
69 {
70 	/** Get the main Gtk struct */
71 	public GDtlsConnection* getDtlsConnectionStruct(bool transferOwnership = false)
72 	{
73 		if (transferOwnership)
74 			ownedRef = false;
75 		return cast(GDtlsConnection*)getStruct();
76 	}
77 
78 
79 	/**
80 	 * Close the DTLS connection. This is equivalent to calling
81 	 * g_dtls_connection_shutdown() to shut down both sides of the connection.
82 	 *
83 	 * Closing a #GDtlsConnection waits for all buffered but untransmitted data to
84 	 * be sent before it completes. It then sends a `close_notify` DTLS alert to the
85 	 * peer and may wait for a `close_notify` to be received from the peer. It does
86 	 * not close the underlying #GDtlsConnection:base-socket; that must be closed
87 	 * separately.
88 	 *
89 	 * Once @conn is closed, all other operations will return %G_IO_ERROR_CLOSED.
90 	 * Closing a #GDtlsConnection multiple times will not return an error.
91 	 *
92 	 * #GDtlsConnections will be automatically closed when the last reference is
93 	 * dropped, but you might want to call this function to make sure resources are
94 	 * released as early as possible.
95 	 *
96 	 * If @cancellable is cancelled, the #GDtlsConnection may be left
97 	 * partially-closed and any pending untransmitted data may be lost. Call
98 	 * g_dtls_connection_close() again to complete closing the #GDtlsConnection.
99 	 *
100 	 * Params:
101 	 *     cancellable = a #GCancellable, or %NULL
102 	 *
103 	 * Returns: %TRUE on success, %FALSE otherwise
104 	 *
105 	 * Since: 2.48
106 	 *
107 	 * Throws: GException on failure.
108 	 */
109 	public bool close(Cancellable cancellable)
110 	{
111 		GError* err = null;
112 
113 		auto __p = g_dtls_connection_close(getDtlsConnectionStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
114 
115 		if (err !is null)
116 		{
117 			throw new GException( new ErrorG(err) );
118 		}
119 
120 		return __p;
121 	}
122 
123 	/**
124 	 * Asynchronously close the DTLS connection. See g_dtls_connection_close() for
125 	 * more information.
126 	 *
127 	 * Params:
128 	 *     ioPriority = the [I/O priority][io-priority] of the request
129 	 *     cancellable = a #GCancellable, or %NULL
130 	 *     callback = callback to call when the close operation is complete
131 	 *     userData = the data to pass to the callback function
132 	 *
133 	 * Since: 2.48
134 	 */
135 	public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
136 	{
137 		g_dtls_connection_close_async(getDtlsConnectionStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
138 	}
139 
140 	/**
141 	 * Finish an asynchronous TLS close operation. See g_dtls_connection_close()
142 	 * for more information.
143 	 *
144 	 * Params:
145 	 *     result = a #GAsyncResult
146 	 *
147 	 * Returns: %TRUE on success, %FALSE on failure, in which
148 	 *     case @error will be set
149 	 *
150 	 * Since: 2.48
151 	 *
152 	 * Throws: GException on failure.
153 	 */
154 	public bool closeFinish(AsyncResultIF result)
155 	{
156 		GError* err = null;
157 
158 		auto __p = g_dtls_connection_close_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
159 
160 		if (err !is null)
161 		{
162 			throw new GException( new ErrorG(err) );
163 		}
164 
165 		return __p;
166 	}
167 
168 	/**
169 	 * Used by #GDtlsConnection implementations to emit the
170 	 * #GDtlsConnection::accept-certificate signal.
171 	 *
172 	 * Params:
173 	 *     peerCert = the peer's #GTlsCertificate
174 	 *     errors = the problems with @peer_cert
175 	 *
176 	 * Returns: %TRUE if one of the signal handlers has returned
177 	 *     %TRUE to accept @peer_cert
178 	 *
179 	 * Since: 2.48
180 	 */
181 	public bool emitAcceptCertificate(TlsCertificate peerCert, GTlsCertificateFlags errors)
182 	{
183 		return g_dtls_connection_emit_accept_certificate(getDtlsConnectionStruct(), (peerCert is null) ? null : peerCert.getTlsCertificateStruct(), errors) != 0;
184 	}
185 
186 	/**
187 	 * Gets @conn's certificate, as set by
188 	 * g_dtls_connection_set_certificate().
189 	 *
190 	 * Returns: @conn's certificate, or %NULL
191 	 *
192 	 * Since: 2.48
193 	 */
194 	public TlsCertificate getCertificate()
195 	{
196 		auto __p = g_dtls_connection_get_certificate(getDtlsConnectionStruct());
197 
198 		if(__p is null)
199 		{
200 			return null;
201 		}
202 
203 		return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) __p);
204 	}
205 
206 	/**
207 	 * Query the TLS backend for TLS channel binding data of @type for @conn.
208 	 *
209 	 * This call retrieves TLS channel binding data as specified in RFC
210 	 * [5056](https://tools.ietf.org/html/rfc5056), RFC
211 	 * [5929](https://tools.ietf.org/html/rfc5929), and related RFCs.  The
212 	 * binding data is returned in @data.  The @data is resized by the callee
213 	 * using #GByteArray buffer management and will be freed when the @data
214 	 * is destroyed by g_byte_array_unref(). If @data is %NULL, it will only
215 	 * check whether TLS backend is able to fetch the data (e.g. whether @type
216 	 * is supported by the TLS backend). It does not guarantee that the data
217 	 * will be available though.  That could happen if TLS connection does not
218 	 * support @type or the binding data is not available yet due to additional
219 	 * negotiation or input required.
220 	 *
221 	 * Params:
222 	 *     type = #GTlsChannelBindingType type of data to fetch
223 	 *     data = #GByteArray is
224 	 *         filled with the binding data, or %NULL
225 	 *
226 	 * Returns: %TRUE on success, %FALSE otherwise
227 	 *
228 	 * Since: 2.66
229 	 *
230 	 * Throws: GException on failure.
231 	 */
232 	public bool getChannelBindingData(GTlsChannelBindingType type, out ByteArray data)
233 	{
234 		GByteArray* outdata = sliceNew!GByteArray();
235 		GError* err = null;
236 
237 		auto __p = g_dtls_connection_get_channel_binding_data(getDtlsConnectionStruct(), type, outdata, &err) != 0;
238 
239 		if (err !is null)
240 		{
241 			throw new GException( new ErrorG(err) );
242 		}
243 
244 		data = new ByteArray(outdata, true);
245 
246 		return __p;
247 	}
248 
249 	/**
250 	 * Returns the name of the current DTLS ciphersuite, or %NULL if the
251 	 * connection has not handshaked or has been closed. Beware that the TLS
252 	 * backend may use any of multiple different naming conventions, because
253 	 * OpenSSL and GnuTLS have their own ciphersuite naming conventions that
254 	 * are different from each other and different from the standard, IANA-
255 	 * registered ciphersuite names. The ciphersuite name is intended to be
256 	 * displayed to the user for informative purposes only, and parsing it
257 	 * is not recommended.
258 	 *
259 	 * Returns: The name of the current DTLS ciphersuite, or %NULL
260 	 *
261 	 * Since: 2.70
262 	 */
263 	public string getCiphersuiteName()
264 	{
265 		auto retStr = g_dtls_connection_get_ciphersuite_name(getDtlsConnectionStruct());
266 
267 		scope(exit) Str.freeString(retStr);
268 		return Str.toString(retStr);
269 	}
270 
271 	/**
272 	 * Gets the certificate database that @conn uses to verify
273 	 * peer certificates. See g_dtls_connection_set_database().
274 	 *
275 	 * Returns: the certificate database that @conn uses or %NULL
276 	 *
277 	 * Since: 2.48
278 	 */
279 	public TlsDatabase getDatabase()
280 	{
281 		auto __p = g_dtls_connection_get_database(getDtlsConnectionStruct());
282 
283 		if(__p is null)
284 		{
285 			return null;
286 		}
287 
288 		return ObjectG.getDObject!(TlsDatabase)(cast(GTlsDatabase*) __p);
289 	}
290 
291 	/**
292 	 * Get the object that will be used to interact with the user. It will be used
293 	 * for things like prompting the user for passwords. If %NULL is returned, then
294 	 * no user interaction will occur for this connection.
295 	 *
296 	 * Returns: The interaction object.
297 	 *
298 	 * Since: 2.48
299 	 */
300 	public TlsInteraction getInteraction()
301 	{
302 		auto __p = g_dtls_connection_get_interaction(getDtlsConnectionStruct());
303 
304 		if(__p is null)
305 		{
306 			return null;
307 		}
308 
309 		return ObjectG.getDObject!(TlsInteraction)(cast(GTlsInteraction*) __p);
310 	}
311 
312 	/**
313 	 * Gets the name of the application-layer protocol negotiated during
314 	 * the handshake.
315 	 *
316 	 * If the peer did not use the ALPN extension, or did not advertise a
317 	 * protocol that matched one of @conn's protocols, or the TLS backend
318 	 * does not support ALPN, then this will be %NULL. See
319 	 * g_dtls_connection_set_advertised_protocols().
320 	 *
321 	 * Returns: the negotiated protocol, or %NULL
322 	 *
323 	 * Since: 2.60
324 	 */
325 	public string getNegotiatedProtocol()
326 	{
327 		return Str.toString(g_dtls_connection_get_negotiated_protocol(getDtlsConnectionStruct()));
328 	}
329 
330 	/**
331 	 * Gets @conn's peer's certificate after the handshake has completed
332 	 * or failed. (It is not set during the emission of
333 	 * #GDtlsConnection::accept-certificate.)
334 	 *
335 	 * Returns: @conn's peer's certificate, or %NULL
336 	 *
337 	 * Since: 2.48
338 	 */
339 	public TlsCertificate getPeerCertificate()
340 	{
341 		auto __p = g_dtls_connection_get_peer_certificate(getDtlsConnectionStruct());
342 
343 		if(__p is null)
344 		{
345 			return null;
346 		}
347 
348 		return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) __p);
349 	}
350 
351 	/**
352 	 * Gets the errors associated with validating @conn's peer's
353 	 * certificate, after the handshake has completed or failed. (It is
354 	 * not set during the emission of #GDtlsConnection::accept-certificate.)
355 	 *
356 	 * Returns: @conn's peer's certificate errors
357 	 *
358 	 * Since: 2.48
359 	 */
360 	public GTlsCertificateFlags getPeerCertificateErrors()
361 	{
362 		return g_dtls_connection_get_peer_certificate_errors(getDtlsConnectionStruct());
363 	}
364 
365 	/**
366 	 * Returns the current DTLS protocol version, which may be
367 	 * %G_TLS_PROTOCOL_VERSION_UNKNOWN if the connection has not handshaked, or
368 	 * has been closed, or if the TLS backend has implemented a protocol version
369 	 * that is not a recognized #GTlsProtocolVersion.
370 	 *
371 	 * Returns: The current DTLS protocol version
372 	 *
373 	 * Since: 2.70
374 	 */
375 	public GTlsProtocolVersion getProtocolVersion()
376 	{
377 		return g_dtls_connection_get_protocol_version(getDtlsConnectionStruct());
378 	}
379 
380 	/**
381 	 * Gets @conn rehandshaking mode. See
382 	 * g_dtls_connection_set_rehandshake_mode() for details.
383 	 *
384 	 * Deprecated: Changing the rehandshake mode is no longer
385 	 * required for compatibility. Also, rehandshaking has been removed
386 	 * from the TLS protocol in TLS 1.3.
387 	 *
388 	 * Returns: %G_TLS_REHANDSHAKE_SAFELY
389 	 *
390 	 * Since: 2.48
391 	 */
392 	public GTlsRehandshakeMode getRehandshakeMode()
393 	{
394 		return g_dtls_connection_get_rehandshake_mode(getDtlsConnectionStruct());
395 	}
396 
397 	/**
398 	 * Tests whether or not @conn expects a proper TLS close notification
399 	 * when the connection is closed. See
400 	 * g_dtls_connection_set_require_close_notify() for details.
401 	 *
402 	 * Returns: %TRUE if @conn requires a proper TLS close notification.
403 	 *
404 	 * Since: 2.48
405 	 */
406 	public bool getRequireCloseNotify()
407 	{
408 		return g_dtls_connection_get_require_close_notify(getDtlsConnectionStruct()) != 0;
409 	}
410 
411 	/**
412 	 * Attempts a TLS handshake on @conn.
413 	 *
414 	 * On the client side, it is never necessary to call this method;
415 	 * although the connection needs to perform a handshake after
416 	 * connecting, #GDtlsConnection will handle this for you automatically
417 	 * when you try to send or receive data on the connection. You can call
418 	 * g_dtls_connection_handshake() manually if you want to know whether
419 	 * the initial handshake succeeded or failed (as opposed to just
420 	 * immediately trying to use @conn to read or write, in which case,
421 	 * if it fails, it may not be possible to tell if it failed before
422 	 * or after completing the handshake), but beware that servers may reject
423 	 * client authentication after the handshake has completed, so a
424 	 * successful handshake does not indicate the connection will be usable.
425 	 *
426 	 * Likewise, on the server side, although a handshake is necessary at
427 	 * the beginning of the communication, you do not need to call this
428 	 * function explicitly unless you want clearer error reporting.
429 	 *
430 	 * Previously, calling g_dtls_connection_handshake() after the initial
431 	 * handshake would trigger a rehandshake; however, this usage was
432 	 * deprecated in GLib 2.60 because rehandshaking was removed from the
433 	 * TLS protocol in TLS 1.3. Since GLib 2.64, calling this function after
434 	 * the initial handshake will no longer do anything.
435 	 *
436 	 * #GDtlsConnection::accept_certificate may be emitted during the
437 	 * handshake.
438 	 *
439 	 * Params:
440 	 *     cancellable = a #GCancellable, or %NULL
441 	 *
442 	 * Returns: success or failure
443 	 *
444 	 * Since: 2.48
445 	 *
446 	 * Throws: GException on failure.
447 	 */
448 	public bool handshake(Cancellable cancellable)
449 	{
450 		GError* err = null;
451 
452 		auto __p = g_dtls_connection_handshake(getDtlsConnectionStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
453 
454 		if (err !is null)
455 		{
456 			throw new GException( new ErrorG(err) );
457 		}
458 
459 		return __p;
460 	}
461 
462 	/**
463 	 * Asynchronously performs a TLS handshake on @conn. See
464 	 * g_dtls_connection_handshake() for more information.
465 	 *
466 	 * Params:
467 	 *     ioPriority = the [I/O priority][io-priority] of the request
468 	 *     cancellable = a #GCancellable, or %NULL
469 	 *     callback = callback to call when the handshake is complete
470 	 *     userData = the data to pass to the callback function
471 	 *
472 	 * Since: 2.48
473 	 */
474 	public void handshakeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
475 	{
476 		g_dtls_connection_handshake_async(getDtlsConnectionStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
477 	}
478 
479 	/**
480 	 * Finish an asynchronous TLS handshake operation. See
481 	 * g_dtls_connection_handshake() for more information.
482 	 *
483 	 * Params:
484 	 *     result = a #GAsyncResult.
485 	 *
486 	 * Returns: %TRUE on success, %FALSE on failure, in which
487 	 *     case @error will be set.
488 	 *
489 	 * Since: 2.48
490 	 *
491 	 * Throws: GException on failure.
492 	 */
493 	public bool handshakeFinish(AsyncResultIF result)
494 	{
495 		GError* err = null;
496 
497 		auto __p = g_dtls_connection_handshake_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
498 
499 		if (err !is null)
500 		{
501 			throw new GException( new ErrorG(err) );
502 		}
503 
504 		return __p;
505 	}
506 
507 	/**
508 	 * Sets the list of application-layer protocols to advertise that the
509 	 * caller is willing to speak on this connection. The
510 	 * Application-Layer Protocol Negotiation (ALPN) extension will be
511 	 * used to negotiate a compatible protocol with the peer; use
512 	 * g_dtls_connection_get_negotiated_protocol() to find the negotiated
513 	 * protocol after the handshake.  Specifying %NULL for the the value
514 	 * of @protocols will disable ALPN negotiation.
515 	 *
516 	 * See [IANA TLS ALPN Protocol IDs](https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids)
517 	 * for a list of registered protocol IDs.
518 	 *
519 	 * Params:
520 	 *     protocols = a %NULL-terminated
521 	 *         array of ALPN protocol names (eg, "http/1.1", "h2"), or %NULL
522 	 *
523 	 * Since: 2.60
524 	 */
525 	public void setAdvertisedProtocols(string[] protocols)
526 	{
527 		g_dtls_connection_set_advertised_protocols(getDtlsConnectionStruct(), Str.toStringzArray(protocols));
528 	}
529 
530 	/**
531 	 * This sets the certificate that @conn will present to its peer
532 	 * during the TLS handshake. For a #GDtlsServerConnection, it is
533 	 * mandatory to set this, and that will normally be done at construct
534 	 * time.
535 	 *
536 	 * For a #GDtlsClientConnection, this is optional. If a handshake fails
537 	 * with %G_TLS_ERROR_CERTIFICATE_REQUIRED, that means that the server
538 	 * requires a certificate, and if you try connecting again, you should
539 	 * call this method first. You can call
540 	 * g_dtls_client_connection_get_accepted_cas() on the failed connection
541 	 * to get a list of Certificate Authorities that the server will
542 	 * accept certificates from.
543 	 *
544 	 * (It is also possible that a server will allow the connection with
545 	 * or without a certificate; in that case, if you don't provide a
546 	 * certificate, you can tell that the server requested one by the fact
547 	 * that g_dtls_client_connection_get_accepted_cas() will return
548 	 * non-%NULL.)
549 	 *
550 	 * Params:
551 	 *     certificate = the certificate to use for @conn
552 	 *
553 	 * Since: 2.48
554 	 */
555 	public void setCertificate(TlsCertificate certificate)
556 	{
557 		g_dtls_connection_set_certificate(getDtlsConnectionStruct(), (certificate is null) ? null : certificate.getTlsCertificateStruct());
558 	}
559 
560 	/**
561 	 * Sets the certificate database that is used to verify peer certificates.
562 	 * This is set to the default database by default. See
563 	 * g_tls_backend_get_default_database(). If set to %NULL, then
564 	 * peer certificate validation will always set the
565 	 * %G_TLS_CERTIFICATE_UNKNOWN_CA error (meaning
566 	 * #GDtlsConnection::accept-certificate will always be emitted on
567 	 * client-side connections, unless that bit is not set in
568 	 * #GDtlsClientConnection:validation-flags).
569 	 *
570 	 * There are nonintuitive security implications when using a non-default
571 	 * database. See #GDtlsConnection:database for details.
572 	 *
573 	 * Params:
574 	 *     database = a #GTlsDatabase
575 	 *
576 	 * Since: 2.48
577 	 */
578 	public void setDatabase(TlsDatabase database)
579 	{
580 		g_dtls_connection_set_database(getDtlsConnectionStruct(), (database is null) ? null : database.getTlsDatabaseStruct());
581 	}
582 
583 	/**
584 	 * Set the object that will be used to interact with the user. It will be used
585 	 * for things like prompting the user for passwords.
586 	 *
587 	 * The @interaction argument will normally be a derived subclass of
588 	 * #GTlsInteraction. %NULL can also be provided if no user interaction
589 	 * should occur for this connection.
590 	 *
591 	 * Params:
592 	 *     interaction = an interaction object, or %NULL
593 	 *
594 	 * Since: 2.48
595 	 */
596 	public void setInteraction(TlsInteraction interaction)
597 	{
598 		g_dtls_connection_set_interaction(getDtlsConnectionStruct(), (interaction is null) ? null : interaction.getTlsInteractionStruct());
599 	}
600 
601 	/**
602 	 * Since GLib 2.64, changing the rehandshake mode is no longer supported
603 	 * and will have no effect. With TLS 1.3, rehandshaking has been removed from
604 	 * the TLS protocol, replaced by separate post-handshake authentication and
605 	 * rekey operations.
606 	 *
607 	 * Deprecated: Changing the rehandshake mode is no longer
608 	 * required for compatibility. Also, rehandshaking has been removed
609 	 * from the TLS protocol in TLS 1.3.
610 	 *
611 	 * Params:
612 	 *     mode = the rehandshaking mode
613 	 *
614 	 * Since: 2.48
615 	 */
616 	public void setRehandshakeMode(GTlsRehandshakeMode mode)
617 	{
618 		g_dtls_connection_set_rehandshake_mode(getDtlsConnectionStruct(), mode);
619 	}
620 
621 	/**
622 	 * Sets whether or not @conn expects a proper TLS close notification
623 	 * before the connection is closed. If this is %TRUE (the default),
624 	 * then @conn will expect to receive a TLS close notification from its
625 	 * peer before the connection is closed, and will return a
626 	 * %G_TLS_ERROR_EOF error if the connection is closed without proper
627 	 * notification (since this may indicate a network error, or
628 	 * man-in-the-middle attack).
629 	 *
630 	 * In some protocols, the application will know whether or not the
631 	 * connection was closed cleanly based on application-level data
632 	 * (because the application-level data includes a length field, or is
633 	 * somehow self-delimiting); in this case, the close notify is
634 	 * redundant and may be omitted. You
635 	 * can use g_dtls_connection_set_require_close_notify() to tell @conn
636 	 * to allow an "unannounced" connection close, in which case the close
637 	 * will show up as a 0-length read, as in a non-TLS
638 	 * #GDatagramBased, and it is up to the application to check that
639 	 * the data has been fully received.
640 	 *
641 	 * Note that this only affects the behavior when the peer closes the
642 	 * connection; when the application calls g_dtls_connection_close_async() on
643 	 * @conn itself, this will send a close notification regardless of the
644 	 * setting of this property. If you explicitly want to do an unclean
645 	 * close, you can close @conn's #GDtlsConnection:base-socket rather
646 	 * than closing @conn itself.
647 	 *
648 	 * Params:
649 	 *     requireCloseNotify = whether or not to require close notification
650 	 *
651 	 * Since: 2.48
652 	 */
653 	public void setRequireCloseNotify(bool requireCloseNotify)
654 	{
655 		g_dtls_connection_set_require_close_notify(getDtlsConnectionStruct(), requireCloseNotify);
656 	}
657 
658 	/**
659 	 * Shut down part or all of a DTLS connection.
660 	 *
661 	 * If @shutdown_read is %TRUE then the receiving side of the connection is shut
662 	 * down, and further reading is disallowed. Subsequent calls to
663 	 * g_datagram_based_receive_messages() will return %G_IO_ERROR_CLOSED.
664 	 *
665 	 * If @shutdown_write is %TRUE then the sending side of the connection is shut
666 	 * down, and further writing is disallowed. Subsequent calls to
667 	 * g_datagram_based_send_messages() will return %G_IO_ERROR_CLOSED.
668 	 *
669 	 * It is allowed for both @shutdown_read and @shutdown_write to be TRUE — this
670 	 * is equivalent to calling g_dtls_connection_close().
671 	 *
672 	 * If @cancellable is cancelled, the #GDtlsConnection may be left
673 	 * partially-closed and any pending untransmitted data may be lost. Call
674 	 * g_dtls_connection_shutdown() again to complete closing the #GDtlsConnection.
675 	 *
676 	 * Params:
677 	 *     shutdownRead = %TRUE to stop reception of incoming datagrams
678 	 *     shutdownWrite = %TRUE to stop sending outgoing datagrams
679 	 *     cancellable = a #GCancellable, or %NULL
680 	 *
681 	 * Returns: %TRUE on success, %FALSE otherwise
682 	 *
683 	 * Since: 2.48
684 	 *
685 	 * Throws: GException on failure.
686 	 */
687 	public bool shutdown(bool shutdownRead, bool shutdownWrite, Cancellable cancellable)
688 	{
689 		GError* err = null;
690 
691 		auto __p = g_dtls_connection_shutdown(getDtlsConnectionStruct(), shutdownRead, shutdownWrite, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
692 
693 		if (err !is null)
694 		{
695 			throw new GException( new ErrorG(err) );
696 		}
697 
698 		return __p;
699 	}
700 
701 	/**
702 	 * Asynchronously shut down part or all of the DTLS connection. See
703 	 * g_dtls_connection_shutdown() for more information.
704 	 *
705 	 * Params:
706 	 *     shutdownRead = %TRUE to stop reception of incoming datagrams
707 	 *     shutdownWrite = %TRUE to stop sending outgoing datagrams
708 	 *     ioPriority = the [I/O priority][io-priority] of the request
709 	 *     cancellable = a #GCancellable, or %NULL
710 	 *     callback = callback to call when the shutdown operation is complete
711 	 *     userData = the data to pass to the callback function
712 	 *
713 	 * Since: 2.48
714 	 */
715 	public void shutdownAsync(bool shutdownRead, bool shutdownWrite, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
716 	{
717 		g_dtls_connection_shutdown_async(getDtlsConnectionStruct(), shutdownRead, shutdownWrite, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
718 	}
719 
720 	/**
721 	 * Finish an asynchronous TLS shutdown operation. See
722 	 * g_dtls_connection_shutdown() for more information.
723 	 *
724 	 * Params:
725 	 *     result = a #GAsyncResult
726 	 *
727 	 * Returns: %TRUE on success, %FALSE on failure, in which
728 	 *     case @error will be set
729 	 *
730 	 * Since: 2.48
731 	 *
732 	 * Throws: GException on failure.
733 	 */
734 	public bool shutdownFinish(AsyncResultIF result)
735 	{
736 		GError* err = null;
737 
738 		auto __p = g_dtls_connection_shutdown_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
739 
740 		if (err !is null)
741 		{
742 			throw new GException( new ErrorG(err) );
743 		}
744 
745 		return __p;
746 	}
747 
748 	/**
749 	 * Emitted during the TLS handshake after the peer certificate has
750 	 * been received. You can examine @peer_cert's certification path by
751 	 * calling g_tls_certificate_get_issuer() on it.
752 	 *
753 	 * For a client-side connection, @peer_cert is the server's
754 	 * certificate, and the signal will only be emitted if the
755 	 * certificate was not acceptable according to @conn's
756 	 * #GDtlsClientConnection:validation_flags. If you would like the
757 	 * certificate to be accepted despite @errors, return %TRUE from the
758 	 * signal handler. Otherwise, if no handler accepts the certificate,
759 	 * the handshake will fail with %G_TLS_ERROR_BAD_CERTIFICATE.
760 	 *
761 	 * GLib guarantees that if certificate verification fails, this signal
762 	 * will be emitted with at least one error will be set in @errors, but
763 	 * it does not guarantee that all possible errors will be set.
764 	 * Accordingly, you may not safely decide to ignore any particular
765 	 * type of error. For example, it would be incorrect to ignore
766 	 * %G_TLS_CERTIFICATE_EXPIRED if you want to allow expired
767 	 * certificates, because this could potentially be the only error flag
768 	 * set even if other problems exist with the certificate.
769 	 *
770 	 * For a server-side connection, @peer_cert is the certificate
771 	 * presented by the client, if this was requested via the server's
772 	 * #GDtlsServerConnection:authentication_mode. On the server side,
773 	 * the signal is always emitted when the client presents a
774 	 * certificate, and the certificate will only be accepted if a
775 	 * handler returns %TRUE.
776 	 *
777 	 * Note that if this signal is emitted as part of asynchronous I/O
778 	 * in the main thread, then you should not attempt to interact with
779 	 * the user before returning from the signal handler. If you want to
780 	 * let the user decide whether or not to accept the certificate, you
781 	 * would have to return %FALSE from the signal handler on the first
782 	 * attempt, and then after the connection attempt returns a
783 	 * %G_TLS_ERROR_BAD_CERTIFICATE, you can interact with the user, and
784 	 * if the user decides to accept the certificate, remember that fact,
785 	 * create a new connection, and return %TRUE from the signal handler
786 	 * the next time.
787 	 *
788 	 * If you are doing I/O in another thread, you do not
789 	 * need to worry about this, and can simply block in the signal
790 	 * handler until the UI thread returns an answer.
791 	 *
792 	 * Params:
793 	 *     peerCert = the peer's #GTlsCertificate
794 	 *     errors = the problems with @peer_cert.
795 	 *
796 	 * Returns: %TRUE to accept @peer_cert (which will also
797 	 *     immediately end the signal emission). %FALSE to allow the signal
798 	 *     emission to continue, which will cause the handshake to fail if
799 	 *     no one else overrides it.
800 	 *
801 	 * Since: 2.48
802 	 */
803 	gulong addOnAcceptCertificate(bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
804 	{
805 		return Signals.connect(this, "accept-certificate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
806 	}
807 }